<!DOCTYPE html>
<html lang="zh - CN">

<head>
    <meta charset="UTF-8">
    <title>随机整数任务</title>
    <style>
        button {
            border - radius: 10px;
            padding: 5px 8px;
            margin: 2px 5px;
        }
    </style>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</head>

<body>
    <textarea id="resultTextarea" rows="10" cols="50"></textarea><br>
    <button id="generateButton">随机产生20个整数</button>
    <button id="findButton">找出能被5整除的整数</button>
    <button id="resetButton">重置</button>
    <script>
        $(document).ready(function () {
    // 存储随机整数的数组
    let randomNumbers = [];

    // 随机产生20个4位整数并排序
    $('#generateButton').on('click', function () {
        randomNumbers = [];
        for (let i = 0; i < 20; i++) {
            let num = Math.floor(Math.random() * 9000 + 1000);
            randomNumbers.push(num);
        }
        randomNumbers.sort((a, b) => a - b);
        let resultText = "随机产生20个4位整数，分别如下：\n";
        resultText += randomNumbers.join('\n');
        resultText += "\n从小到大排序后结果为：\n";
        resultText += randomNumbers.join('\n');
        $('#resultTextarea').val(resultText);
    });

    // 找出能被5整除的整数
    $('#findButton').on('click', function () {
        let divisibleByFive = randomNumbers.filter(num => num % 5 === 0);
        let resultText = "能被5整除的整数有：\n";
        resultText += divisibleByFive.join('\n');
        $('#resultTextarea').val(resultText);
    });

    // 重置文本框
    $('#resetButton').on('click', function () {
        $('#resultTextarea').val('');
    });
});
    </script>
</body>

</html>